import 'package:flutter/material.dart';
import 'package:hkzf/widgets/common_form_item.dart';
import 'package:hkzf/widgets/common_picker.dart';

class CommonSelectFormItem extends StatelessWidget {
  const CommonSelectFormItem(
      {Key key, this.label, this.options, this.value, this.onChange})
      : super(key: key);
  final String label;
  final List<String> options;
  final int value;
  final ValueChanged<int> onChange;

  @override
  Widget build(BuildContext context) {
    return CommonFormItem(
      label: label,
      contentBuilder: (BuildContext context) {
        return GestureDetector(
          behavior: HitTestBehavior.translucent,
          onTap: () {
            var result = CommonPicker.showPicker(
                context: context, options: options, value: value);
            result.then((selectedValue) {
              print(selectedValue);
              if (value != selectedValue &&
                  selectedValue != null &&
                  onChange != null) {
                onChange(selectedValue);
              }
            });
          },
          child: Container(
            height: 40,
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    options[value],
                    style: TextStyle(fontSize: 16),
                  ),
                  Icon(Icons.keyboard_arrow_right)
                ]),
          ),
        );
      },
    );
  }
}
